<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{:get_system_config('site_name')}</title>
    {:get_system_config('site_tongji')}
    {include file='common/_require'/}
    <link rel="stylesheet" href="/static/lib/quill/quill.snow.css">
    <style>
        body {
            background-color: #eee;
            line-height: 1.5;
        }

        .wapper {
            margin-top: 15px;
            background-color: #fff;
            padding: 15px;
        }

        .data-item {
            display: inline-block;
            margin-right: 15px;
        }
    </style>
</head>

<body>

    <div class="layui-container">
        <div class="wapper">
            <h1>{:get_system_config('site_name')}</h1>
            {notempty name='gotoMainDomain'}
            <h4>当前并非主站，请跳转至主站 <a href="//{$gotoMainDomain}">{$gotoMainDomain}</a> </h4>
            {/notempty}
            <h3>{:get_system_config('site_desc')}</h3>
        </div>

        <div class="wapper">
            <div class="layui-card">
                <div class="layui-card-header">
                    托管访问统计
                </div>
                <div class="layui-card-body">
                    <div class="data-item">
                        <span class="data-title">托管中的域名</span>
                        <span class="data-value online-count">{$domain_count}</span>
                    </div>
                    <div class="data-item">
                        <span class="data-title">托管访问次数</span>
                        <span class="data-value online-count">{$domain_visit_count}</span>
                    </div>
                </div>
            </div>


        </div>
        <div class="ul-group-title-2">
            自动解析
        </div>
        <div class="wapper">
            <div class="layui-card">
                <div class="layui-card-header">
                    <span>自动解析域名</span>
                    <span class="layui-word-aux">我提交过的域名</span>
                    {empty name='user_uid'}
                    <a href="{$login_url}" class="layui-word-aux">当前未登录,前往登陆</a>
                    {else /}
                    <a href="{:url('logout')}" class="layui-word-aux">退出登陆</a>
                    {/empty}
                </div>
                <div class="layui-card-body">

                    <div class="">
                        <ul>
                            {volist name='list_domain' id='vo'}
                            <li class="item" data-id="{$vo.id}">
                                <span class="layui-word-aux">{$vo.domain}</span>
                                <span class="layui-word-aux">cname:{:get_system_config('main_domain')}</span>
                                <span>
                                    <div class="layui-btn layui-btn-sm delete">删除</div>
                                </span>
                            </li>
                            {/volist}
                            {empty name='list_domain'}
                            <li>暂无域名</li>
                            {/empty}
                        </ul>
                    </div>
                </div>
            </div>


        </div>
        <div class="wapper">
            <div class="layui-card">
                <div class="layui-card-header">提交域名</div>
                <div class="layui-card-body">
                    <form class="layui-form" action="{:url('saveDomain')}" method="POST">
                        <div class="layui-form-item">
                            <label class="layui-form-label">域名</label>
                            <div class="layui-input-block">
                                <input type="text" name="domain" required lay-verify="required" placeholder="请输入域名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span>用户UID</span>
                                {empty name='user_uid'}
                                <a href="{$login_url}" class="layui-word-aux">当前未登录,前往登陆</a>
                                {else /}
                                <a href="{:url('logout')}" class="layui-word-aux">退出登陆</a>
                                {/empty}
                            </label>
                            <div class="layui-input-block">
                                <input type="text" name="user_uid" required lay-verify="required" readonly placeholder="登录后提交"
                                       value="{$Request.session.user_uid}" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
        <div class="ul-group-title-2">
            域名主页
        </div>
        <div class="wapper">
            <div class="layui-card">
                <div class="layui-card-header">
                    <span>域名信息主页</span>
                    <span class="layui-word-aux">我提交过的域名</span>
                    {empty name='user_uid'}
                    <a href="{$login_url}" class="layui-word-aux">当前未登录,前往登陆</a>
                    {else /}
                    <a href="{:url('logout')}" class="layui-word-aux">退出登陆</a>
                    {/empty}
                </div>
                <div class="layui-card-body">

                    <div class="">
                        <ul>
                            {volist name='list_domain_info' id='vo'}
                            <li class="item" data-id="{$vo.id}">
                                <span class="layui-word-aux">{$vo.domain}</span>
                                <span class="layui-word-aux">cname:{:get_system_config('main_domain')}</span>
                                <span class="layui-word-aux">{$vo.title}</span>
                                <span class="layui-word-aux">{$vo.beian}</span>
                                <span class="layui-word-aux">{$vo.beian_name}</span>
                                <span>
                                    <a class="layui-btn layui-btn-sm" href="{:url('index',['domain_info_id'=>$vo.id])}#edit-domain-info">编辑</a>
                                    <div class="layui-btn layui-btn-sm delete-info">删除</div>
                                </span>
                            </li>
                            {/volist}
                            {empty name='list_domain'}
                            <li>暂无域名</li>
                            {/empty}
                        </ul>
                    </div>
                </div>
            </div>


        </div>
        <div class="wapper" id="edit-domain-info">
            <div class="layui-card">
                <div class="layui-card-header">提交域名</div>
                <div class="layui-card-body">
                    <form class="layui-form" action="{:url('saveDomainInfo')}" method="POST">
                        <input type="hidden" name="id" value="{$model_domain_info.id|default=''}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">域名</label>
                            <div class="layui-input-block">
                                <input type="text" name="domain" value="{$model_domain_info.domain|default=''}" required lay-verify="required"
                                       placeholder="请输入域名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">站点名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="title" value="{$model_domain_info.title|default=''}" required lay-verify="required"
                                       placeholder="请输入站点名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">备案号</label>
                            <div class="layui-input-block">
                                <input type="text" name="beian" value="{$model_domain_info.beian|default=''}" required lay-verify="required"
                                       placeholder="请输入备案号" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">备案名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="beian_name" value="{$model_domain_info.beian_name|default=''}" required lay-verify="required"
                                       placeholder="请输入备案名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">
                                <span>用户UID</span>
                                {empty name='user_uid'}
                                <a href="{$login_url}" class="layui-word-aux">当前未登录,前往登陆</a>
                                {else /}
                                <a href="{:url('logout')}" class="layui-word-aux">退出登陆</a>
                                {/empty}
                            </label>
                            <div class="layui-input-block">
                                <input type="text" name="user_uid" required lay-verify="required" readonly placeholder="登录后提交"
                                       value="{$Request.session.user_uid}" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
        <div class="ul-group-title-2">
            文档
        </div>

        <div class="wapper">
            <div class="ql-editor">{:get_system_config('user_agreement_html')}</div>
        </div>
    </div>

    <script>

        $('.delete').click(function () {
            var item = this;
            var parent = $(item).closest('.item');

            layer.confirm('确定要删除吗?', function () {
                $.post('{:url("deleteDomain")}', {
                    id: $(parent).data('id')
                }, function (result) {
                    layer.msg('删除成功');
                    $(parent).remove();
                });
            });
        });
        $('.delete-info').click(function () {
            var item = this;
            var parent = $(item).closest('.item');

            layer.confirm('确定要删除吗?', function () {
                $.post('{:url("deleteDomainInfo")}', {
                    id: $(parent).data('id')
                }, function (result) {
                    layer.msg('删除成功');
                    $(parent).remove();
                });
            });
        });

        function visitDomain() {
            $.get('{:url("visitDomain")}', function (result) {
                $.get('http://' + result.data.domain + '/visit.html?t=' + Math.random());

                setTimeout(() => {
                    visitDomain();
                }, 9000);
            });
        }
        visitDomain()

    </script>
</body>

</html>